const express = require("express");
const router = express.Router();
const homehot = require("./data/home/homehot")
const url = require("url");
const searchData=require("./data/Search")
const detailData=require("./data/details")
const commentData=require("./data/comment")
const orderData=require("./data/order")

/**
 * 首页热门数据
 */
router.get("/home/hot1",(req,res) =>{
    res.send({
        status:200,
        result:homehot.hot1
    })
})

router.get("/home/hot2",(req,res) =>{
    res.send({
        status:200,
        result:homehot.hot2
    })
})

//搜索的router
router.get("/search",(req, res)=>{
    const search = url.parse(req.url,true).query.search;
    res.send({
        status:200,
        result:searchData
    })
})

/**
* 搜索页面，使用mock
*/
/*router.get("/mock", (req, res) => {
    // const search = url.parse(req.url, true).query.search;
    let data = Mock.mock({
        hasMore: true,
        'data|5': [{
            "id|+1":Random.integer(),
            title: Random.csentence(5, 8),
            houseType: "17/19层| 4室1厅 - 273.97 ㎡",
            price: "<h3>130000</h3>",
            rentType: Random.cword(2),
            img: Random.image('800x600', Random.color(), '#FFF', 'png', Random.cword(5))
        }]
    })
    res.send({
        status: 200,
        result: data
    })
})*/

//搜索页面的详情
router.get("/details",(req,res)=>{
    const id = url.parse(req.url,true).query.id;
    console.log(id)
        res.send(detailData)

})

//登陆接口的
router.post("/login",(req, res)=>{
    const {username,password}=req.body;
    if (username && password){
        res.send({
            status:200,
            token:"enjy23rsdfe3fsveq.23r23sfdvfv.asdfqf4ag34ghdfjtkjhq",
            nick:username
        })
    }else {
        res.send({
            status:400,
            msg:"用户名或者密码错误"
            }
        )}

})

//评价的信息
router.get("/comment",(req, res)=>{
    const id = url.parse(req.url).query.id;
    console.log(id)
    res.send({
        status:200,
        result:commentData
    })
})

//订单的详情展示
router.get("/order",(req, res)=>{
    const username=url.parse(req.url,true).query.username
    res.send({
        status:200,
        result:orderData
    })
})

//提交订单评价的接口
router.post("/order/comment",(req, res)=>{
    const {id,content}=req.body
    res.send({
        msg:"提交评价成功",
        status:200
    })
})

module.exports = router;